class Solution {
public:
    int cal(int num1, int num2, char op) {
        if (op == '+') {
            return num1 + num2;
        } else if (op == '-') {
            return num1 - num2;
        } else if (op == '*') {
            return num1 * num2;
        } else if (op == '/') {
            return num1 / num2;
        }
        return 0;
    }
    int get_num(string num) {
        int ret = 0;
        int pos = 0, flg = 0;
        if (num[0] == '-') {
            pos++;
            flg = 1;
        }
        while (pos < num.size()) {
            ret = ret * 10 + (num[pos] - '0');
            pos++;
        }
        if (flg) {
            ret = -ret;
        }
        return ret;
    }
    int evalRPN(vector<string>& tokens) {
        stack<int> st;
        for (int i = 0; i < tokens.size(); i++) {
            if (tokens[i][0] >= '0' && tokens[i][0] <= '9' ||
                tokens[i][0] == '-' && tokens[i].size() > 1) {
                int num = get_num(tokens[i]);
                st.push(num);
            } else {
                if (st.size() >= 2) {
                    int num1 = st.top();
                    st.pop();
                    int num2 = st.top();
                    st.pop();
                    cout<<num2<<' '<<num1<<endl;
                    int t=cal(num2, num1, tokens[i][0]);
                    st.push(t);
                    cout<<t<<endl;
                }
            }
        }
        return st.top();
    }
};
